package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api("区域服务管理")
public class ServeController {
    @Resource
    private IServeService serveService;

    @GetMapping("/page")
    @ApiOperation("分页查询区域服务接口")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO dto) {
        return serveService.pageServe(dto);
    }

    @PostMapping("/batch")
    @ApiOperation("添加/批量添加区域服务接口")
    public void batch(
            @RequestBody @ApiParam(name = "serveUpsertReqDTOS", value = "serveUpsertReqDTOS", required = true)
            List<ServeUpsertReqDTO> serveUpsertReqDTOS
    ) {
        serveService.batch(serveUpsertReqDTOS);
    }

    @PutMapping("/{id}")
    @ApiOperation("修改区域服务价格接口")
    public void updatePrice(
            @PathVariable("id") @ApiParam(name = "id", value = "区域服务id", required = true) Long id,
            @RequestParam("price") @ApiParam(name = "price", value = "区域价格", required = true) BigDecimal price
    ) {
        serveService.updatePrice(id, price);
    }

    @PutMapping("/onSale/{id}")
    @ApiOperation("区域服务上架接口")
    public void onSale(@PathVariable("id") @ApiParam(name = "id", value = "区域服务id", required = true) Long id) {
        serveService.onSala(id);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除区域服务接口")
    public void delete(@PathVariable("id") @ApiParam(name = "id", value = "区域服务id", required = true) Long id) {
        serveService.delete(id);
    }

    @PutMapping("/offSale/{id}")
    @ApiOperation("区域服务下架接口")
    public void offSale(@PathVariable("id") @ApiParam(name = "id", value = "区域服务id", required = true) Long id) {
        serveService.offSale(id);
    }

    @PutMapping("/onHot/{id}")
    @ApiOperation("区域服务设置热门接口")
    public void onHot(@PathVariable("id") @ApiParam(name = "id", value = "区域服务id", required = true) Long id) {
        serveService.onHot(id);
    }

    @PutMapping("/offHot/{id}")
    @ApiOperation("区域服务取消热门接口")
    public void offHot(@PathVariable("id") @ApiParam(name = "id", value = "区域服务id") Long id) {
        serveService.offHot(id);
    }
}
